{% extends 'base/base.html' %}
{% block content %}
    <div class="row" style="margin-top: 10px">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="btn btn-sm btn-success add-btn">添加项目</div>
                    {#<form>#}
                    <div class="box-tools">
                        <div class="input-group input-group-sm" style="width: 150px;">
                            <input type="text" name="table_search" class="form-control pull-right" placeholder="Search">
                            <div class="input-group-btn">
                                <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
                            </div>
                        </div>
                    </div>
                    {#</form>#}
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover">
                        <tr>
                            <th>序号</th>
                            <th>项目名</th>
                            <th>责任人</th>
                            <th>研发人员</th>
                            <th>测试人员</th>
                            <th>运维人员</th>
                            <th>项目目录</th>
                            <th>git地址</th>
                            <th>语言</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        {% for p in projectList %}
                            <tr>
                                <td>{{ forloop.counter }}</td>
                                <td>{{ p.name }}</td>

                                <td>
                                    {% for b in p.boss.all %}
                                        {{ b.name }},
                                    {% endfor %}
                                </td>
                                <td>
                                    {% for du in p.dev_user.all %}
                                        {{ du.name }},
                                    {% endfor %}

                                </td>
                                <td>
                                    {% for tu in p.test_user.all %}
                                        {{ tu.name }},
                                    {% endfor %}
                                </td>
                                <td>
                                    {% for ou in p.ops_user.all %}
                                        {{ ou.name }},
                                    {% endfor %}
                                </td>

                                <td>{{ p.path }}</td>
                                <td>{{ p.git_path }}</td>
                                <td>{{ p.get_language_display }}</td>
                                <td>{{ p.get_status_display }}</td>
                                <td>
                                    <div data-url="{% url 'projectEdit' p.pk %}" class="btn btn-sm btn-warning edit_btn">
                                        编辑
                                    </div>
                                    <div data-url="{% url 'projectDetail' p.pk %}" class="btn btn-sm btn-info info_btn">
                                        详情
                                    </div>
                                    <div data-url="{% url 'projectDel' p.pk %}" class="btn btn-sm btn-danger del_btn">
                                        删除
                                    </div>
                                </td>
                            </tr>
                        {% endfor %}
                    </table>
                </div>
                <!-- /.box-body -->
            </div>
            <ul class="pagination">{{ page_html }}</ul>
            <!-- /.box -->
        </div>
    </div>
{% endblock %}

{% block js %}
    <script>
        $("#project_list").addClass("active")
        $(".add-btn").on("click", function () {
            ui.box({
                title: "添加用户",
                remote:{% url 'projectAdd' %},
            })
        })

        $(".edit_btn").on("click", function () {
            url = $(this).attr("data-url")
            console.log("url=", url)
            ui.box({
                title: "编辑用户",
                remote: url
            })
        })

        $(".info_btn").on("click", function () {
            url = $(this).attr("data-url")
            console.log("url=", url)
            ui.box({
                title: "项目详情",
                remote: url,
                size: 'xlg'
            })
        })

        $(".del_btn").on("click", function () {
            url = $(this).attr("data-url")
            console.log("url=", url)
            ui.confirm("确认删除此条记录吗？", function () {
                Net.get({
                    url: url,
                    reload: true
                })
            })
        })
    </script>
{% endblock %}
